package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.MemberReservationService;
import com.zzyl.nursing.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController {
    @Autowired
    private MemberReservationService memberReservationService;

    /**
     *  查询取消预约数量
     * @return
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Integer count = memberReservationService.getCancelledReservationCount();
        return R.ok(count);
    }

    /**
     * 新增预约
     */
    @PostMapping()
    @ApiOperation("新增预约")
    public AjaxResult add(@RequestBody Reservation memberReservation) {
        memberReservation.setStatus(0);
        memberReservationService.save(memberReservation);
        return success();
    }

    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("/countByTime")
    public AjaxResult countByTime(Long time ) {
      List<ReservationVo>  reservationVo = memberReservationService.countByTime(time);
        return success(reservationVo);
    }
}